#include "MainFrame/CentralWidget/ImageViewWidget.h"
#include "MainFrame/CentralWidget/ImageViewArea.h"
#include <QScrollArea>
#include <QHBoxLayout>

ImageViewWidget::ImageViewWidget(QWidget *parent, Qt::WindowFlags f) :
    QWidget(parent, f),
    m_pScrollArea(nullptr),
    m_pImageViewArea(nullptr)
{
    initWidget();
    connectSignalToSlots();
}

ImageViewWidget::~ImageViewWidget()
{

}

void ImageViewWidget::initWidget()
{
    m_pScrollArea = new QScrollArea(this);
    m_pScrollArea->setWidgetResizable(true);
    m_pScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    m_pScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    m_pScrollArea->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);

    m_pImageViewArea = new ImageViewArea(m_pScrollArea);
    m_pScrollArea->setWidget(m_pImageViewArea);

    QHBoxLayout* Layout = new QHBoxLayout;
    Layout->addWidget(m_pScrollArea, 0, 0);
    Layout->setMargin(5);
    this->setLayout(Layout);
}

void ImageViewWidget::connectSignalToSlots()
{
    connect(m_pImageViewArea, SIGNAL(cursorPosChanged(QPoint&)),
            this, SIGNAL(cursorPosChanged(QPoint&)));
}

void ImageViewWidget::updateImageViewWidget()
{
    m_pImageViewArea->updateImageViewArea();
}

void ImageViewWidget::setEnCurToolState(const ToolState &enCurToolState)
{
    m_pImageViewArea->setEnCurToolState(enCurToolState);
}
